package com.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.activity.bean.OpusBean;
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.utils.ImageViewUtil;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class PersonalAdapter extends GroupedRecyclerViewAdapter {


    public ArrayList<OpusBean> data = new ArrayList();

    public PersonalAdapter(Context context) {
        super(context);

    }


    @Override
    public boolean hasHeader(int groupPosition) {

        return false;
    }

    @Override
    public boolean hasFooter(int groupPosition) {
        return false;
    }

    @Override
    public int getGroupCount() {

        return 1;
    }

    @Override
    public int getHeaderViewType(int groupPosition) {

        return 0;
    }

    @Override
    public int getChildrenCount(int groupPosition) {

        return data.size();

    }

    @Override
    public int getChildViewType(int groupPosition, int childPosition) {
        return TYPE_CHILD;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return 0;
    }

    @Override
    public int getFooterLayout(int viewType) {
        return 0;
    }

    @Override
    public int getChildLayout(int viewType) {


        return R.layout.item_personal_cell;
    }

    @Override
    public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) {


    }

    @Override
    public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) {

    }


    @Override
    public void onBindChildViewHolder(BaseViewHolder holder, int groupPosition, int childPosition) {


        ((PersonalHolder) holder).setData(data.get(childPosition));

    }

    //
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_CHILD) {

            View view = LayoutInflater.from(mContext).inflate(getChildLayout(viewType), parent, false);

            return new PersonalHolder(view);

        }
        return super.onCreateViewHolder(parent, viewType);
    }


    public class PersonalHolder extends BaseViewHolder {

        @BindView(R.id.iv_icon)
        ImageView ivIcon;
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.iv_user_icon)
        ImageView ivUserIcon;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_num)
        TextView tvNum;

        public PersonalHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void setData(OpusBean data) {

            if(data.images().size()>0){
                ImageViewUtil.loadImage(data.images().get(0),ivIcon,mContext);
            }else {
                ivIcon.setImageResource(R.drawable.meinv);
            }


            tvName.setText(data.getUsernickname());
            tvContent.setText(data.getWorkscontent());
            tvNum.setText(data.getWorkspraisenum());
            ImageViewUtil.loadCircleImage(data.getUsericon(),ivUserIcon,mContext);

        }


    }

}
